home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1989 / 05 / test.c < prev    next >
C/C++ Source or Header  |  1989-07-03  |  2KB  |  71 lines

  1. /*
  2.     TEST.C - Test the twll functions
  3. */
  4.  
  5.  
  6. #include "stdio.h"
  7. #include "malloc.h"
  8. #include "coop.h"
  9.  
  10.  
  11. /* This is the TWLL header that contains the top of the list pointer */
  12.  
  13. struct TWLL_HEAD header={0};
  14.  
  15.  
  16. main()
  17. {
  18.     int      x;
  19.     struct DATA_TWLL        *twll_item;
  20.     struct MY_DATA_TWLL     *my_twll_item;
  21.     struct OTHER_DATA_TWLL  *other_twll_item;
  22.  
  23.  
  24.     /* add 3 entries of each type to the list */
  25.     for (x=3;x;x--) {
  26.         twll_item=                      /* create a new DATA_TWLL */
  27.             (struct DATA_TWLL *)
  28.             calloc(sizeof(struct DATA_TWLL),1);
  29.  
  30.         add_data_twll(&header,twll_item,DATA);
  31.         twll_item->x=x;                                
  32.  
  33.         my_twll_item=               /* create a new MY_DATA_TWLL */
  34.              (struct MY_DATA_TWLL *)
  35.             calloc(sizeof(struct MY_DATA_TWLL),1);
  36.  
  37.         add_data_twll(&header,my_twll_item,MY_DATA);
  38.         strcpy(my_twll_item->a,"Sample.");             
  39.  
  40.         other_twll_item=                /* create a new OTHER_DATA_TWLL */
  41.              (struct OTHER_DATA_TWLL *)
  42.             calloc(sizeof(struct OTHER_DATA_TWLL),1);
  43.  
  44.         add_data_twll(&header,other_twll_item,OTHER_DATA);
  45.         other_twll_item->a=x+100;                   
  46.         }
  47.  
  48.  
  49.     /* print the contents of the list */
  50.     printf("printing lines in current list \n");
  51.     for(twll_item=header.top;
  52.         twll_item;
  53.         twll_item=twll_item->inherit.next) {
  54.  
  55.         switch (twll_item->inherit.type) {
  56.             case DATA:
  57.                 print_data_twll(twll_item);
  58.                 break;
  59.             case MY_DATA:
  60.                 print_my_data_twll(twll_item);
  61.                 break;
  62.             case OTHER_DATA:
  63.                 print_other_data_twll(twll_item);
  64.                 break;
  65.             }
  66.         }
  67.  
  68.     exit(0);        
  69. }   
  70.  
  71.